<template>
  <div class="pop-up-child" v-if="showHotProduct">
    <header class="header">
      <p class="title" v-text="sheetTitle"></p>
      <div class="close" @click="close">
        <Iconfont iconClass="cha1"/>
      </div>
    </header>
    <div class="list-content">
      <ul class="pop-child-content" v-infinite-scroll="loadMore" infinite-scroll-disabled="busy" infinite-scroll-distance="10">
        <li class="pop-list" v-for="(v,index) in hotProductArr" key="index" @click="clickImg(v.imgLink)">
          <div class="con-img">
            <img :src="v.img+'?x-oss-process=image/resize,m_fixed,h_190,w_335'" v-on:click.self.prevent>
          </div>
        </li>
      </ul>
      <p class="tip-text">{{tipText}}</p>
    </div>
  </div>
</template>
<script>
export default {
  components: {
  },
  props:{
    roomInfo:String,//房间信息
    sheetTitle: String//标题
	},
  data() {
    return {
      showHotProduct: true,
      hotProductArr: [],
      tipText: "",//上拉加载 底部文本提示
    }
  },
  methods: {
    close() {
      this.$emit("formChildMsg",{
        type: "footerActionSheetClose",
        data: ''
      })
    },
    loadMore: function() {
      this.busy = true//放在数据请求{this.getAnchorArray()}的外面，避免不断重复加载的现象

      this.tipText = "数据加载中..."
        // 多次加载数据
      setTimeout(() => {//延迟，为了 防抖
        this.page++;
        this.gethotProduct();
      }, 10);
    },
    gethotProduct() {
      this.$http.get('/h5live/getImgLinkList', {
        params: {
          anchor: this.roomInfo.roomInfo.anchor,//主播id
        }
      } )
      .then(res => {
        if(res.data.code == '000000'){
          if (res.data.data.length) {
            this.hotProductArr = res.data.data
            this.busy = false;//数据请求成功，打开 上拉加载
            if (res.data.data.length < 10) {
              this.busy = true;//禁用
              this.tipText = "没有更多数据了"
            }
          } else {
            this.busy = true; //禁用
            this.page = 0
            this.tipText = "没有更多数据了"
          }
        }
      })
      .catch(response => {
        console.log(response);
      });
    },
    clickImg(imglink) {
      if (imglink) {
        const item = {
          'link':imglink,
          'linkType':1
        }
         fun.linkUrlFloatVideo(item);
      }
    }
  },
};
</script>
<style scoped>
.pop-up-child {
  width: 100%;
  min-height: 220px;
  background: #fff;
  position: absolute;
  left: 0;
  bottom: 0;
  z-index: 1001;
  border-radius: 20px 20px 0px 0px;
}

.pop-up-child .header {
  line-height: 64px;
  text-align: center;
  position: relative;
}

.pop-up-child .title {
  font-size: 28px;
  font-weight: bold;
  color: #666666;
}

.pop-up-child .close {
  position: absolute;
  top: 0;
  right: 0;
}

.pop-up-child .iconcha1 {
  padding: 0 30px;
  font-size: 18px;
  color: #c8c9cc;
}

.list-content {
  width: 100vw;
  max-height: calc(56vh - 64px);
  overflow-y: scroll;
}

.pop-child-content {
  padding-bottom: 20px;
  margin-left: 30px;
  margin-right: 30px;
  display: flex;
  flex-wrap: wrap;
}

.pop-list {
  width: 335px;
  height: 190px;
  margin-top: 20px;
  margin-left: 20px;
}

.pop-list:nth-child(odd) {
  margin-left: 0px;
}

.con-img img {
  display: block;
  width: 335px;
  height: 190px;
  border-radius: 6px;
}

.tip-text {
  width: 100%;
  height: 80px;
  line-height: 80px;
  color: #999999;
  text-align: center;
  font-size: 26px;
  margin-top: 30px;
}

</style>
